<script>
import pagination from '@crud/PaginationCustom.vue'
import CRUD, { presenter, header, form, crud } from '@/components/Crud/customCrud'
import udOperation from '@crud/UD.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import CustomImageUpload from '@/components/ImageUpload/CustomImageUpload.vue'

const defaultForm = {
  id: null,
  name: '', // 客户端名称
  icon: '', // 密钥
  url: '', // IP白名单
  px: 0, // 流速
  pt: '',
  state: true // 是否启用
}
export default {
  name: 'LinkManager',
  components: { CustomImageUpload, crudOperation, udOperation, pagination },
  cruds() {
    return CRUD({
      title: '快速链接管理',
      url: 'rest/api/portal/manager/v1/link',
      props: {
        searchToggle: true
      }
    })
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  methods: {
    checkboxT(row, rowIndex) {
      // return row.id !==
      return true
    }
  }
}
</script>

<template>
  <div class="app-container">
    <el-card class="box-card">
      <div class="custom-header">
        <crudOperation show="" />
      </div>
      <!--表格渲染-->
      <div class="custom-table">
        <el-table
          ref="table"
          v-loading="crud.loading"
          :data="crud.data"
          style="width: 100%;"
          @selection-change="crud.selectionChangeHandler"
        >
          <el-table-column
            :selectable="checkboxT"
            type="selection"
            width="55"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="name"
            label="名称"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="url"
            label="地址"
          />
          <el-table-column prop="px" label="排序" />
          <el-table-column
            v-permission="['admin', 'user:edit', 'user:del']"
            label="操作"
            width="115"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <udOperation
                :data="scope.row"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页组件-->
      <div class="box-pager">
        <pagination />
      </div>
    </el-card>
    <!--表单渲染-->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible.sync="crud.status.cu > 0"
      :title="crud.status.title"
      width="700px"
    >
      <el-form
        ref="form"
        :inline="true"
        :model="form"
        size="small"
        label-width="120px"
      >
        <el-form-item
          :rules="[{ required: true, message: '请输入链接名称', trigger: 'blur' }]"
          label="链接名称"
          prop="name"
        >
          <el-input v-model="form.name" placeholder="请输入链接名称" style="width: 400px;" />
        </el-form-item>
        <el-form-item
          label="地址"
          :rules="[{ required: true, message: '请输入打开地址', trigger: 'blur' }]"
          prop="url"
        >
          <el-input v-model="form.url" placeholder="请输入打开地址" style="width: 400px;" />
        </el-form-item>
        <el-form-item
          label="排序"
          :rules="[{ required: true, message: '请输入排序值', trigger: 'blur' }]"
          prop="px"
        >
          <el-input-number v-model="form.px" placeholder="请输入排序值" style="width: 400px;" />
        </el-form-item>
        <el-form-item
          label="图标"
          prop="icon"
          :rules="[{ required: true, message: '请上传图标', trigger: 'change' }]"
          style="width: 100%"
        >
          <custom-image-upload v-model="form.icon">
            <div slot="reference">
              <img v-if="form.icon" :src="form.icon" class="avatar" style="height: 60px">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </div>
          </custom-image-upload>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group
            v-model="form.state"
          >
            <el-radio
              v-for="item in enable"
              :key="item.id"
              :label="item.value"
            >{{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button
          :loading="crud.status.cu === 2"
          type="primary"
          @click="crud.submitCU"
        >确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style scoped>
.el-card ::v-deep .el-card__body {
  width: 100%;
  display: flex;
  flex-flow: row wrap;
}

.box-card {
  min-height: 100vh;
  width: 100%;
}

.custom-header {
  width: 100%;
  height: 60px;
}

.custom-table {
  width: 100%;
  height: auto;
}

.box-pager {
  width: 100%;
  height: 50px;
  margin-top: 20px;
}
</style>
